const path = require('path');
const webpack = require('webpack');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
//导入内存中生成HTML页面的插件
//插件都要放入plugins节点中去
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports={
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    mode: 'development',
    //devServer: {
        //open: true,
        //port: 3000,
        //contentBase: 'src',
        //hot: true
    //},
    plugins: [
    
        // make sure to include the plugin for the magic
        new VueLoaderPlugin(),
        
        //new webpack.HotModuleReplacementPlugin()，
        new htmlWebpackPlugin({
            template: './src/index.html'
        })
    ],
    module:{//配置所有第三方模块加载器
        rules:[
            { test:/\.css$/, use: ['style-loader', 'css-loader']},
            { test:/\.less$/, use: ['style-loader', 'css-loader', 'less-loader']},
            { test:/\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader']},
            { test:/\.(jpg|png|gif|bmp|jpeg)$/, use: 'url-loader?limit=36777&name=[hash:8]-[name].[ext]'},
            //大于等于不转为base64格式，小于则转为base64格式
            { test:/\.(ttf|eot|svg|woff|woff2)$/, use: 'url-loader'},
            //{ test:/\.js$/, use: 'babel-loader', exclude: /node_modules/},
            { test: /\.js$/,exclude: /(node_modules|bower_components)/,use: {loader: "babel-loader"}},
            {test:/\.vue$/,use:'vue-loader'},
            //不排除node_modules,则会把其下所有js打包编译，会消耗cpu，打包慢
        ]
    }
}



//使用webpack-dev-server自动打包编译
//使用命令$ npm i webpack-dev-server -D
//项目中安装，所以无法使用脚本命令
//webpack打包命令：webpack .\src\main.js -o .\dist\bundle.js --mode=development
//打包生成的bundle.js文件，没有存入到实际的物理磁盘，托管到电脑内存，速度快




